package sjtu.ist.warehouse4ws.service;

import java.util.ArrayList;
import java.util.List;

import sjtu.ist.warehouse4ws.dao.DomainModelStateDao;
import sjtu.ist.warehouse4ws.dao.cust.CustDomainModelStateDao;
import sjtu.ist.warehouse4ws.model.CustDomainmodelstate;
import sjtu.ist.warehouse4ws.model.Domainmodelstate;
import sjtu.ist.warehouse4ws.tool.Constants;
import sjtu.ist.warehouse4ws.tool.PropertyHelper;

public class DomainModelStateServiceImpl implements DomainModelStateService {
	private DomainModelStateDao domainModelStateDao;
	private CustDomainModelStateDao custDomainModelStateDao;
	@Override
	public List<Domainmodelstate> getDomainModelStateList(String domainModelId) {
		// TODO Auto-generated method stub
		return (List<Domainmodelstate>)domainModelStateDao.findAllDomainModelStates(domainModelId);
	}
	//依赖注入DAO组件的setter方法
	public void setDomainModelStateDao(
			DomainModelStateDao domainModelStateDao) {
		this.domainModelStateDao = domainModelStateDao;
	}
	public void setCustDomainModelStateDao(
			CustDomainModelStateDao custDomainModelStateDao) {
		this.custDomainModelStateDao = custDomainModelStateDao;
	}
	@Override
	public void saveDomainmodelstate(Domainmodelstate domainmodelstate, int companyId) {
		// TODO Auto-generated method stub
		if(companyId==Constants.ADMIN_COMPANY_ID){
			domainModelStateDao.savaDomainmodelstate(domainmodelstate);
		}else{
			CustDomainmodelstate cdms=new CustDomainmodelstate();
			PropertyHelper.copyProperties(domainmodelstate, cdms);
			custDomainModelStateDao.savaCustDomainmodelstate(cdms);
		}		
	}
	@Override
	public List<Domainmodelstate> getByGroupAndVersion(String groupId,
			String version, int companyId) {
		// TODO Auto-generated method stub
		if(companyId==Constants.ADMIN_COMPANY_ID){
			return domainModelStateDao.getByGroupAndVersion(groupId,version);
		}else{
			List<Domainmodelstate> list=new ArrayList<Domainmodelstate>();
			List<CustDomainmodelstate> clist=custDomainModelStateDao.getByGroupAndVersion(groupId,version);
			for(CustDomainmodelstate cdms:clist){
				Domainmodelstate dms=new Domainmodelstate();
				PropertyHelper.copyProperties(cdms, dms);
				list.add(dms);
			}
			return list;
		}
	}
}
